package com.feicheng.lanniao.controller.weChatNativePay.constant;
import com.feicheng.lanniao.util.WechatPayUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
@PropertySource(value = "classpath:wechatPayConfig.properties", encoding = "UTF-8")
public class WechatPayConfig implements InitializingBean {


    @Value("${nativeUnifiedOrder}")
    private String gateway;

    @Value("${appsecret}")     //扫码支付暂时用不上了
    private String appsecret;

    @Value("${mchid}")
    private String mchid;  //商户号

    @Value("${appid}")
    private String appid;

    @Value("${key}")
    private String key;

    @Value("${mchSerialNo}")
    private String mchSerialNo;

    @Value("${certificatesUrl}")
    private String certificatesUrl;


    @Value("${keyPath}")
    private String keyPath;

    @Value("${logo}")
    private String logo;

    //异步接收微信支付结果通知的回调地址
    @Value("${carBuyInfoCallback}")
    private String carBuyInfoCallback;

    @Value("${carRentInfoCallback}")
    private String carRentInfoCallback;

    @Value("${carRentalInfoCallback}")
    private String carRentalInfoCallback;

    @Value("${carSellInfoCallback}")
    private String carSellInfoCallback;

    @Value("${houseBuyInfoCallback}")
    private String houseBuyInfoCallback;

    @Value("${houseRentInfoCallback}")
    private String houseRentInfoCallback;

    @Value("${houseRentalInfoCallback}")
    private String houseRentalInfoCallback;

    @Value("${houseSellInfoCallback}")
    private String houseSellInfoCallback;

    @Value("${payCallback}")
    private String callBack;


    // 定义全局容器 保存微信平台证书公钥
    public static Map<String, X509Certificate> CERTIFICATE_MAP = new ConcurrentHashMap<>();

    public static void certificateMap(String serialNo) {
    }

    public static String GATEWAY;
    public static String APP_SECRET;
    public static String MCH_ID;
    public static String APPID;
    public static String KEY;
    public static String MCH_SERIAL_NO;
    public static String CERTIFICATES_URL;
    public static String KEY_PATH;
    public static PrivateKey PRIVATE_KEY;
    public static String LOGO;
    public static String CAR_BUY_INFO_CALLBACK;
    public static String CAR_RENT_INFO_CALLBACK;
    public static String CAR_RENTAL_INFO_CALLBACK;
    public static String CAR_SELL_INFO_CALLBACK;
    public static String HOUSE_BUY_INFO_CALLBACK;
    public static String HOUSE_RENT_INFO_CALLBACK;
    public static String HOUSE_RENTAL_INFO_CALLBACK;
    public static String HOUSE_SELL_INFO_CALLBACK;
    public static String CALL_BACK;


    @Override
    public void afterPropertiesSet() throws Exception {
        GATEWAY = gateway;
        APP_SECRET = appsecret;
        MCH_ID = mchid;
        APPID = appid;
        KEY = key;
        MCH_SERIAL_NO = mchSerialNo;
        CERTIFICATES_URL = certificatesUrl;
                                                            //"D:/公司微信支付/文档和资料/1613522293_20210827_cert/apiclient_key.pem"
        KEY_PATH = keyPath;                                 //"/opt/stackcoding_wechatPayTest/1613522293_20210827_cert/apiclient_key.pem"
        PRIVATE_KEY = WechatPayUtils.getPrivateKey(KEY_PATH);
        LOGO = logo;
        CAR_BUY_INFO_CALLBACK = carBuyInfoCallback;
        CAR_RENT_INFO_CALLBACK = carRentInfoCallback;
        CAR_RENTAL_INFO_CALLBACK = carRentalInfoCallback;
        CAR_SELL_INFO_CALLBACK = carSellInfoCallback;
        HOUSE_BUY_INFO_CALLBACK = houseBuyInfoCallback;
        HOUSE_RENT_INFO_CALLBACK = houseRentInfoCallback;
        HOUSE_RENTAL_INFO_CALLBACK = houseRentalInfoCallback;
        HOUSE_SELL_INFO_CALLBACK = houseSellInfoCallback;
        CALL_BACK = callBack;
    }
}
